<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {
    public function index(){
    		$this->display();
    }
    public function checkUsers(){
    		$username=$_POST['username'];
    		$pwd=$_POST['pwd'];
    		//连接数据库查询数据
    		$users = M("users");
    		$data['username'] = $username;
    		$data['pwd'] = $pwd;
    		$res = $users->where($data)->find();
    		if($res){
    			$info['info']="用户名密码正确";
    			$info['status']=1;
    			//存session
    			session("username",$username);
    		}else{
    			$info['info']="用户名或密码错误";
    			$info['status']=2;
    		}
    		//返还状态
    		$this->ajaxReturn($info);
    }
    public function exitlogin(){
    		session("username",null);
    		$info['info']="清除成功";
    		$info['status']=1;
    		$this->ajaxReturn($info);
    }
    
    public function getshopcar(){
    		$person['username'] = $_SESSION['username'];
    		$users = M("users");
    		$data = $users->where($person)->find();
    		$shopcar['userid'] = $data['id'];
    		$shopcart = M("shopcar");
    		$res = $shopcart->where($shopcar)->select();
    		if($res){
    			for($i = 0;$i<count($res);$i++){
	    			$goods = M("good");
	    			$good['id']=$res[$i]['goodid'];
	    			$goodinfo=$goods->where($good)->find();
		    		$goodinfo["imgurl"]=explode(',',$goodinfo["imgurl"])[0];
	    			$info['goodinfo'][$i]=$goodinfo;
	    		}
    			$info['data']=$res;
    			$info['count']=$res[0]['goodid'];
    			$info['status']=1;
    		}else{
    			$info['data']="";
    			$info['status']=2;
    		}
    		$this->ajaxReturn($info);
    		
    }
    
    
}

?>